
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>浏览页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
        <style>
            .layui-btn-primary {
                color: #000;
                font-size: 14px;
                border-color: rgb(210, 210, 210);
                background: 0px 0px;
            }
        </style>
    </head>
    <body class="pear-container">
    
        <!-- 顶部查询表单 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form top-search-from">
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block" style="width: 320px;margin-left: 52px">
                            <div class="layui-btn-group ">
                                <a class="layui-btn layui-btn-normal layui-btn-1"  onclick="type_select(1);" style="width: 100px;">水上推广</a>
                                <a class="layui-btn layui-btn-primary layui-btn-2" onclick="type_select(2);" style="width: 100px;">水下推广</a>
                                <a class="layui-btn layui-btn-primary layui-btn-3" onclick="type_select(3);" style="width: 100px;">海外推广</a>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">ID</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="text" autocomplete="off" name="novel_sn" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="hidden" autocomplete="off" name="title[]" value="like" class="layui-input inline-block">
                                <input type="text" autocomplete="off" name="title[]" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">客户端在线</label>
                        <div class="layui-input-block">
                            <div name="is_online" id="is_online" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">标签</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="hidden" autocomplete="off" name="labels[]" value="find" class="layui-input inline-block">
                                <input type="text" autocomplete="off" name="labels[]" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">自定义标签</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block">
                                <input type="hidden" autocomplete="off" name="custom_tags[]" value="find" class="layui-input inline-block">
                                <input type="text" autocomplete="off" name="custom_tags[]" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商家</label>
                        <div class="layui-input-block">
                            <div name="business_id" id="business_id" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">指令模板</label>
                        <div class="layui-input-block">
                            <div name="ai_image_command_id" id="ai_image_command_id" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <div name="status" id="status" value="" ></div>
                        </div>
                    </div>

                    <div class="layui-form-item spread_type_1">
                        <label class="layui-form-label">任务状态</label>
                        <div class="layui-input-block">
                            <div name="task_status" id="task_status" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item spread_type_2"  style="display: none">
                        <label class="layui-form-label">推广状态</label>
                        <div class="layui-input-block">
                            <div name="under_status" id="under_status" value="" ></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">上线时间</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block" id="start_time">
                                <input type="text" autocomplete="off" name="start_time[]" id="start_time-date-start" class="layui-input inline-block" placeholder="开始时间">
                                -
                                <input type="text" autocomplete="off" name="start_time[]" id="start_time-date-end" class="layui-input inline-block" placeholder="结束时间">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">同步时间</label>
                        <div class="layui-input-block">
                            <div class="layui-input-block" id="created_at">
                                <input type="text" autocomplete="off" name="created_at[]" id="created_at-date-start" class="layui-input inline-block" placeholder="开始时间">
                                -
                                <input type="text" autocomplete="off" name="created_at[]" id="created_at-date-end" class="layui-input inline-block" placeholder="结束时间">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label"></label>
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
                            <i class="layui-icon layui-icon-search"></i>查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md" lay-submit lay-filter="table-reset">
                            <i class="layui-icon layui-icon-refresh"></i>重置
                        </button>
                    </div>
                    <div class="toggle-btn">
                        <a class="layui-hide">展开<i class="layui-icon layui-icon-down"></i></a>
                        <a class="layui-hide">收起<i class="layui-icon layui-icon-up"></i></a>
                    </div>
                </form>
            </div>
        </div>
        
        <!-- 数据表格 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="data-table" lay-filter="data-table"></table>
            </div>
        </div>

        <!-- 表格顶部工具栏 -->
        <script type="text/html" id="table-toolbar">
            <!--<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.novel.index.insert">-->
                <!--<i class="layui-icon layui-icon-add-1"></i>新增-->
            <!--</button>-->

            <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.novel.index.delete">
                <i class="layui-icon layui-icon-delete"></i>删除
            </button>
            <button class="pear-btn pear-btn-primary pear-btn-md spread_type_1" lay-event="upload" permission="app.admin.novel.index.upload">
                批量导入更新
            </button>
            <button class="pear-btn pear-btn-primary pear-btn-md spread_type_2" lay-event="upload2" permission="app.admin.novel.index.upload2">
                批量导入短篇小说
            </button>
            <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="business" permission="app.admin.business.index.index">
                商家管理
            </button>
            <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="custom_tags" permission="app.admin.novel.index.customtags">
                批量自定义标签
            </button>
            <button class="pear-btn pear-btn-primary pear-btn-md spread_type_1_2" lay-event="generate_plan" permission="app.admin.novel.index.generateplan">
                批量生成方案
            </button>
        </script>

        <!-- 表格行工具栏 -->
        <script type="text/html" id="table-bar">
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="chapter" permission="app.admin.novel.chapter.select">创作章节</button>
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="plan" permission="app.admin.plan.index.select">方案</button>
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="works" permission="app.admin.user.works.select">作品</button>
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.novel.index.update">编辑</button>
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.novel.index.delete">删除</button>
        </script>

        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script src="/app/admin/admin/js/common.js"></script>
        <script src="/app/admin/admin/js/functions.js"></script>
        <script src="/app/admin/admin/js/md5.js"></script>
        
        <script>
            let spread_type = 1;
            let spread_type_hide_1 = false;
            let spread_type_hide_2 = true;
            let spread_type_hide_3 = true;
            let search_where = {};

            // 相关常量
            const NOVEL_SN = layui.url().search['novel_sn']??'';
            const PRIMARY_KEY = "id";
            let SELECT_API = "/app/admin/novel/index/select";
            const UPDATE_API = "/app/admin/novel/index/update";
            const DELETE_API = "/app/admin/novel/index/delete";
            const INSERT_URL = "/app/admin/novel/index/insert";
            const UPDATE_URL = "/app/admin/novel/index/update";
            const UPLOAD_URL = "/app/admin/novel/index/upload";
            const UPLOAD_URL_2 = "/app/admin/novel/index/upload2";
            const CUSTOMTAGS_URL = "/app/admin/novel/index/customtags";
            const GENERATEPLAN_URL = "/app/admin/novel/index/generateplan";
            const CHAPTER_URL = "/app/admin/novel/chapter/index";
            const BUSINESS_URL = "/app/admin/novel/business/index";

            let where = {};
            if(NOVEL_SN){
                layui.$('input[name="novel_sn"]').val(NOVEL_SN);
                where = {"novel_sn":NOVEL_SN};
                // 获取数据库记录
                layui.use(["form", "util", "popup"], function () {
                    $ = layui.$;
                    $.ajax({
                        url: SELECT_API + location.search,
                        dataType: "json",
                        async:false,
                        headers: get_header({"novel_sn":NOVEL_SN}),
                        success: function (res) {
                            spread_type = res.data[0].spread_type;
                            type_select(spread_type);
                            // ajax返回失败
                            if (res.code) {
                                layui.popup.failure(res.msg);
                            }
                        }
                    });
                });
            }else{
                where = {"status":1,"task_status":2,"under_status":"","spread_type":spread_type};
                type_select(spread_type);
            }

            // 字段 指令模板 ai_image_command_id
            layui.use(["jquery", "xmSelect", "popup"], function() {
                layui.$.ajax({
                    url: "/app/admin/image/aiimagecommand/select?format=select&limit=1000",
                    dataType: "json",
                    async:true,
                    headers: get_header({"format":"select"}),
                    success: function (res) {
                        let initValue = [];
                        layui.xmSelect.render({
                            el: "#ai_image_command_id",
                            name: "ai_image_command_id",
                            filterable: true,
                            data: res.data,
                            initValue: initValue,
                            model: {"icon":"hidden","label":{"type":"text"}},
                            clickClose: true,
                            radio: true,
                        })
                        if (res.code) {
                            layui.popup.failure(res.msg);
                        }
                    }
                });
            });

            // 字段 添加时间 created_at
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#created_at",
                    range: ["#created_at-date-start", "#created_at-date-end"],
                    type: "datetime",
                    mark: date_today_mark,
                });
            })

            // 字段 添加时间 created_at
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#start_time",
                    range: ["#start_time-date-start", "#start_time-date-end"],
                    type: "datetime",
                    mark: date_today_mark,
                });
            })

            // 字段 状态 status
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#status",
                    name: "status",
                    filterable: true,
                    initValue: [1],
                    data: [{"value":"1","name":"是"},{"value":"0","name":"否"}],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true,
                })
            });
            
            // 字段 任务状态 task_status
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#task_status",
                    name: "task_status",
                    filterable: true,
                    initValue: [2],
                    data: [
                        {"value":"","name":"全部"},
                        {"value":"0","name":"无"},
                        {"value":"1","name":"待审核"},
                        {"value":"2","name":"已上线"},
                        {"value":"3","name":"已下架"},
                        {"value":"4","name":"审核不过"},
                    ],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true,
                })
            });

            // 字段 任务状态 task_status
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#under_status",
                    name: "under_status",
                    filterable: true,
                    initValue: [1],
                    data: [
                        {"value":"","name":"全部"},
                        {"value":"1","name":"上架"},
                        {"value":"2","name":"下架"},
                    ],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true,
                })
            });

            // 字段 任务状态 is_online
            layui.use(["jquery", "xmSelect"], function() {
                layui.xmSelect.render({
                    el: "#is_online",
                    name: "is_online",
                    filterable: true,
                    initValue: [],
                    data: [
                        {"value":"","name":"全部"},
                        {"value":"1","name":"在线"},
                    ],
                    model: {"icon":"hidden","label":{"type":"text"}},
                    clickClose: true,
                    radio: true,
                })
            });

            layui.use(["form", "common"], function() {
                layui.$('.spread_type_2').hide();
            });

            // 表格渲染
            layui.use(["table", "form", "common", "popup", "util", 'tab', ], function() {
                let table = layui.table;
                let form = layui.form;
                let $ = layui.$;
                let common = layui.common;
                let util = layui.util;

                // 编辑或删除行事件
                table.on("tool(data-table)", function(obj) {
                    if (obj.event === "remove") {
                        remove(obj);
                    } else if (obj.event === "edit") {
                        edit(obj);
                    } else if (obj.event === "chapter") {
                        chapter(obj);
                    } else if (obj.event === "plan") {
                        plan(obj);
                    } else if (obj.event === "works") {
                        works(obj);
                    }
                });

                // 表格顶部工具栏事件
                table.on("toolbar(data-table)", function(obj) {
                    if (obj.event === "add") {
                        add();
                    } else if (obj.event === "refresh") {
                        refreshTable();
                    } else if (obj.event === "batchRemove") {
                        batchRemove(obj);
                    } else if (obj.event === "upload") {
                        batchUpload(obj);
                    } else if (obj.event === "upload2") {
                        batchUpload2(obj);
                    } else if (obj.event === "business") {
                        business(obj);
                    } else if (obj.event === "custom_tags") {
                        customTags(obj);
                    } else if (obj.event === "generate_plan") {
                        generatePlan(obj);
                    }
                });

                // 表格顶部搜索事件
                form.on("submit(table-query)", function(data) {
                    search_where = where = searchWhere(data.field);
                    if(spread_type==1){
                        if('task_status' in search_where){
                            where.task_status =search_where.task_status
                        }else{
                            where.task_status = 2;
                        }
                        where.under_status = '';
                    }else if(spread_type==2){
                        if('under_status' in search_where){
                            where.under_status =search_where.under_status
                        }else{
                            where.under_status = 1;
                        }
                        where.task_status = '';
                    }else if(spread_type==3){
                        where.under_status = '';
                        where.task_status = '';
                    }
                    where.spread_type = spread_type;
                    table.reload("data-table", {
                        page: {
                            curr: 1
                        },
                        where: where,
                        headers: get_header(where)
                    })
                    return false;
                });
                
                // 表格顶部搜索重置事件
                form.on("submit(table-reset)", function(data) {
                    where = {};
                    if(spread_type==1){
                        if('task_status' in search_where){
                            where.task_status =search_where.task_status
                        }else{
                            where.task_status = 2;
                        }
                        where.under_status = '';
                    }else if(spread_type==2){
                        if('under_status' in search_where){
                            where.under_status =search_where.under_status
                        }else{
                            where.under_status = 1;
                        }
                        where.task_status = '';
                    }else if(spread_type==3){
                        where.under_status = '';
                        where.task_status = '';
                    }
                    where.spread_type = spread_type;
                    table.reload("data-table", {
                        where: where,
                        headers: get_header(where)
                    })
                });

                // 表格排序事件
                table.on("sort(data-table)", function(obj){
                    where.field=obj.field;
                    where.order=obj.type;
                    if(spread_type==1){
                        if('task_status' in search_where){
                            where.task_status =search_where.task_status
                        }else{
                            where.task_status = 2;
                        }
                        where.under_status = '';
                    }else if(spread_type==2){
                        if('under_status' in search_where){
                            where.under_status =search_where.under_status
                        }else{
                            where.under_status = 1;
                        }
                        where.task_status = '';
                    }else if(spread_type==3){
                        where.under_status = '';
                        where.task_status = '';
                    }
                    where.spread_type = spread_type;

                    table.reload("data-table", {
                        initSort: obj,
                        scrollPos: "fixed",
                        where: where,
                        headers: get_header(where)
                    });
                });

                // 表格新增数据
                let add = function() {
                    layer.open({
                        type: 2,
                        title: "新增",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"500px", common.isModile()?"100%":"450px"],
                        content: INSERT_URL
                    });
                }

                // 批量导入
                let batchUpload = function() {
                    layer.open({
                        type: 2,
                        title: "批量导入",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"500px", common.isModile()?"100%":"250px"],
                        content: UPLOAD_URL
                    });
                }

                // 批量导入
                let batchUpload2 = function() {
                    layer.open({
                        type: 2,
                        title: "批量导入",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"500px", common.isModile()?"100%":"250px"],
                        content: UPLOAD_URL_2
                    });
                }

                // 批量自定义标签
                let customTags = function(obj) {
                    let checkIds = common.checkField(obj, PRIMARY_KEY);
                    if (checkIds === "") {
                        layui.popup.warning("未选中数据");
                        return false;
                    }
                    layer.open({
                        type: 2,
                        title: "批量自定义标签",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"550px", common.isModile()?"100%":"250px"],
                        content: CUSTOMTAGS_URL+'?ids='+checkIds.split(",")
                    });
                }

                // 批量生成方案
                let generatePlan = function(obj) {
                    let checkIds = common.checkField(obj, PRIMARY_KEY);
                    if (checkIds === "") {
                        layui.popup.warning("未选中数据");
                        return false;
                    }
                    layer.open({
                        type: 2,
                        title: "批量生成方案",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"1000px", common.isModile()?"100%":"600px"],
                        content: GENERATEPLAN_URL+'?ids='+checkIds.split(",")
                    });
                }

                // 商家管理
                let business = function() {
                    layer.open({
                        type: 2,
                        title: "商家管理",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"80%", common.isModile()?"100%":"80%"],
                        content: BUSINESS_URL+'?spread_type='+spread_type
                    });
                }

                // 创作章节
                let chapter = function(obj) {
                    let value = obj.data['novel_sn'];
                    layer.open({
                        type: 2,
                        title: "创作章节",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"100%", common.isModile()?"100%":"100%"],
                        content: CHAPTER_URL + "?" + "novel_sn=" + value
                    });
                }

                // 方案管理
                let plan = function(obj) {
                    let value = obj.data[PRIMARY_KEY];

                    layer.open({
                        type: 2,
                        title: "方案管理",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"100%", common.isModile()?"100%":"100%"],
                        content: "/app/admin/plan/index?" + "novel_sn=" + obj.data["novel_sn"]
                    });
                }

                // 作品
                let works = function(obj) {
                    let value = obj.data[PRIMARY_KEY];

                    layer.open({
                        type: 2,
                        title: "作品列表",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"100%", common.isModile()?"100%":"100%"],
                        content: "/app/admin/user/works/index?" + "novel_sn=" + obj.data["novel_sn"]
                    });
                }

                // 表格编辑数据
                let edit = function(obj) {
                    let value = obj.data[PRIMARY_KEY];
                    layer.open({
                        type: 2,
                        title: "修改",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"90%", common.isModile()?"100%":"95%"],
                        content: UPDATE_URL + "?" + PRIMARY_KEY + "=" + value
                    });
                }

                // 删除一行
                let remove = function(obj) {
                    return doRemove(obj.data[PRIMARY_KEY]);
                }

                // 删除多行
                let batchRemove = function(obj) {
                    let checkIds = common.checkField(obj, PRIMARY_KEY);
                    if (checkIds === "") {
                        layui.popup.warning("未选中数据");
                        return false;
                    }
                    doRemove(checkIds.split(","));
                }

                // 执行删除
                let doRemove = function (ids) {
                    let data = {};
                    data[PRIMARY_KEY] = ids;
                    layer.confirm("确定删除?", {
                        icon: 3,
                        title: "提示"
                    }, function(index) {
                        layer.close(index);
                        let loading = layer.load();
                        $.ajax({
                            url: DELETE_API,
                            data: data,
                            dataType: "json",
                            type: "post",
                            async:true,
                            headers: get_header(data),
                            success: function(res) {
                                layer.close(loading);
                                if (res.code) {
                                    return layui.popup.failure(res.msg);
                                }
                                return layui.popup.success("操作成功", refreshTable);
                            }
                        })
                    });
                }

                // 刷新表格数据
                window.refreshTable = function(param) {
                    table.reloadData("data-table", {
                        scrollPos: "fixed"
                    });
                }
            })

            function table_render() {
                layui.use(["table", "form", "common", "popup", "util", 'tab', ], function() {
                    let table = layui.table;
                    let form = layui.form;
                    let $ = layui.$;
                    let util = layui.util;

                    // 表头参数
                    let cols = [
                        {
                            type: "checkbox", align: "center"
                        },{
                            title: "ID",align: "center", field: "novel_sn",minWidth:100,sort:true,
                        },{
                            title: "标题",align: "center", field: "title",minWidth:150,
                        },{
                            title: "封面图",align: "center", field: "main_image",minWidth:100, templet: function (d) {
                                return '<img src="'+encodeURI(d['main_image'])+'" style="max-width:32px;max-height:32px;" alt="" />'
                            }
                        },{
                            title: "商家",align: "center", field: "business_name",minWidth:100,
                        },{
                            title: "语言",align: "center", field: "lang",minWidth:100,
                        },{
                            title: "状态",align: "center", field: "status",minWidth:100, templet: function (d) {
                                let field = "status";
                                form.on("switch("+field+")", function (data) {
                                    let load = layer.load();
                                    let postData = {};
                                    postData[field] = data.elem.checked ? 1 : 0;
                                    postData[PRIMARY_KEY] = this.value;
                                    $.ajax({
                                        url: UPDATE_API,
                                        dateType: "json",
                                        type: "POST",
                                        data:postData,
                                        headers: get_header(postData),
                                        success: function (res) {
                                            layer.close(load);
                                            if (res.code) {
                                                return layui.popup.failure(res.msg, function () {
                                                    data.elem.checked = !data.elem.checked;
                                                    form.render();
                                                });
                                            }
                                            return layui.popup.success("操作成功");
                                        }
                                    });
                                });
                                let checked = d[field] === 1 ? "checked" : "";
                                return '<input type="checkbox" value="'+util.escape(d[PRIMARY_KEY])+'" lay-filter="'+util.escape(field)+'" lay-skin="switch" lay-text="'+util.escape('')+'" '+checked+'/>';
                            }
                        }
                        , {field: 'plan_nums', title: '方案数量',width:100,sort:true}
                        , {field: 'ai_image_template_name', title: '生图指令模板',width:120}
                        , {field: 'task_id', title: '推广任务ID',width:130,hide:spread_type_hide_1}
                        , {field: 'book_id', title: '小说ID',width:130,hide:spread_type_hide_2}
                        , {field: 'task_status', title: '任务状态',width:100,hide:spread_type_hide_1}
                        , {field: 'under_status', title: '推广状态',width:100,hide:spread_type_hide_2}
                        , {field: 'payment_allocate_ratio', title: '佣金比例',width:120,sort:true,hide:spread_type_hide_1}
                        , {field: 'commission', title: '佣金/单',width:120,sort:true,hide:spread_type_hide_2}

                        , {field: 'really_income', title: '真实收益',width:120,sort:true}
                        , {field: 'really_spread_num', title: '真实推广人数',width:150,sort:true}
                        , {field: 'task_settle_type', title: '支付分成',width:100,hide:spread_type_hide_1}
                        , {field: 'task_refund_period', title: '退款周期（天）',width:100,hide:spread_type_hide_1}
                        , {field: 'start_time', title: '上线时间',width:160,sort:true}
                        , {field: 'created_at', title: '同步时间',width:160,sort:true}
                        , {field: 'first_category', title: '一级分类',width:120,sort:true,hide:spread_type_hide_2}
                        , {field: 'second_category', title: '二级分类',width:120,sort:true,hide:spread_type_hide_2}
                        , {field: 'labels', title: '标签',width:180,sort:true}
                        , {field: 'custom_tags', title: '自定义标签',width:150,sort:true}
                        , {field: 'words_num', title: '字数',width:120,sort:true,hide:spread_type_hide_2}
                        , {field: 'operate_tags', title: '运营标签',width:180,sort:true,hide:spread_type_hide_2}
                        , {field: 'desc', title: '简介',width:180}
                        ,{
                            title: "操作", toolbar: "#table-bar", align: "center", fixed: "right", width: 260,
                        }
                    ];

                    if(spread_type==1){
                        if('task_status' in search_where){
                            where.task_status =search_where.task_status
                        }else{
                            where.task_status = 2;
                        }
                        where.under_status = '';
                    }else if(spread_type==2){
                        if('under_status' in search_where){
                            where.under_status =search_where.under_status
                        }else{
                            where.under_status = 1;
                        }
                        where.task_status = '';
                    }else if(spread_type==3){
                        where.task_status = '';
                        where.under_status = '';
                    }
                    where.spread_type = spread_type;
                    // 渲染表格
                    table.render({
                        elem: "#data-table",
                        url: SELECT_API,
                        page: true,
                        where: where,
                        headers: get_header(where),
                        limits: [10, 20, 50, 100, 200, 500],
                        limit: 10,
                        cols: [cols],
                        skin: "line",
                        size: "lg",
                        toolbar: "#table-toolbar",
                        autoSort: false,
                        defaultToolbar: [{
                            title: "刷新",
                            layEvent: "refresh",
                            icon: "layui-icon-refresh",
                        }, "filter", "print", "exports"],
                        done: function () {
                            layer.photos({photos: 'div[lay-id="data-table"]', anim: 5});
                            if(spread_type==1){
                                layui.$('.spread_type_1').show();
                                layui.$('.spread_type_2').hide();
                            }else if(spread_type==2){
                                layui.$('.spread_type_2').show();
                                layui.$('.spread_type_1').hide();
                            }else if(spread_type==3){
                                layui.$('.spread_type_2').hide();
                                layui.$('.spread_type_1').hide();
                                layui.$('.spread_type_1_2').hide();
                            }
                        }
                    });
                });
            }

            function business_list() {
                // 字段 商家 business_id
                layui.use(["jquery", "xmSelect", "popup"], function() {
                    layui.$.ajax({
                        url: "/app/admin/novel/business/select?format=select&limit=1000&spread_type="+spread_type,
                        dataType: "json",
                        async:true,
                        headers: get_header({"format":"select","spread_type":spread_type}),
                        success: function (res) {
                            layui.xmSelect.render({
                                el: "#business_id",
                                name: "business_id",
                                filterable: true,
                                data: res.data,
                                model: {"icon":"hidden","label":{"type":"text"}},
                                clickClose: true,
                                radio: true,
                            })
                            if (res.code) {
                                layui.popup.failure(res.msg);
                            }
                        }
                    });
                });
            }

            function type_select(type) {
                spread_type = type;
                layui.$('.layui-btn-'+spread_type).removeClass("layui-btn-primary").addClass('layui-btn-normal');
                layui.$('.layui-btn-'+spread_type).siblings('a').addClass("layui-btn-primary").removeClass('layui-btn-normal');
                if(spread_type==1){
                    spread_type_hide_1 = false;
                    spread_type_hide_2 = true;
                    spread_type_hide_3 = true;
                }else if(spread_type==2){
                    spread_type_hide_2 = false;
                    spread_type_hide_1 = true;
                    spread_type_hide_3 = true;
                }else if(spread_type==3){
                    spread_type_hide_3 = false;
                    spread_type_hide_1 = true;
                    spread_type_hide_2 = true;
                }

                //商家下拉选择
                business_list();

                // 表格渲染
                table_render();
            }
        </script>
    </body>
</html>
